<?php
/**
* openDocument library kit
*
* @link http://webappkit.net
* @package pathnodes
* @subpackage od
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* root class for openDocument master classes
* @abstract
* @uses odContainer_zip
* @uses odContainer_folder
* @uses odContainer_xml
* @uses odContentNode
*/
class odFileNode extends pathNode {
/*--------------------------------------------------------------------
CONSTRUCTOR
--------------------------------------------------------------------*/
    /**
    * constructor alias
    * @access public
    */
    function odFileNode($path=null) {
        $this->__construct($path);
    }/**/
    
    /**
    * "real" constructor
    * @access public
    */
    function __construct($path=null) {
        parent::__construct($path);
        // trying to build container
        $this->_getContainer();
    }/**/
/*--------------------------------------------------------------------
PUBLIC STATIC METHODS
--------------------------------------------------------------------*/
    /**
    * 
    * @static
    * @param
    * @return 
    * /
    function () {
        
    }/**/
/*--------------------------------------------------------------------
PUBLIC INSTANCE METHODS
--------------------------------------------------------------------*/
    /**
     * force download file (zip container)
     * @access public
     * @return bool
     */
    function download($filename=null) {
        // if container is not zip:
        if (!is_a($this->container,'odcontainer_zip')) {
            // cloning container to a zip one
            $container=odContainer_zip::cloneFrom($this->container);
        } else {
            $container=&$this->container;
        }
        return $container->download($filename);
    }/**/

    /**
     * prints content to browser
     * @access public
     * @ return bool
     */
    function printContent() {
        $content=&$this->container->getContent();
        echo $content->getDocumentXml();
        return true;
    }

    /**
    * injects data into content's <database-display> elements.
    * (usually from a database)
    * @param array $data
    * @access public
    * @return int count of modified elements
    */
    function insertFusionRow($data=array(),$table=null,$db=null) {
        $content=&$this->container->getContent();
        return $content->insertFusionRow($data,$table,$db);
    }/**/
    
    /**
    *
    * @param
    * @access public
    * @return
    * /
    function () {

    }/**/
/*--------------------------------------------------------------------
VARS / MEMBERS
--------------------------------------------------------------------*/
    /**
    * @var object container instance : odcontainer_zip|odContainer_xml|odContainer_folder
    */
    var $container;
    
/*--------------------------------------------------------------------
PRIVATE / PROTECTED METHODS
--------------------------------------------------------------------*/
    /**
    * builds if necessary and returns $this->container
    * returns null/false if fails
    * @access protected
    * @return object container instance : odcontainer_zip|odContainer_xml|odContainer_folder
    */
    function & _getContainer() {
        // trying to build container instance
        if (!$this->container and $this->path) {
            // detecting type
            switch (true) {
                // folder
                case odContainer_folder::selfDetector($this->path):
                    $this->container=&new odContainer_folder($this->path);
                    // $this->container->getContent();
                    break;
                // xml
                // zip
                case odContainer_zip::selfDetector($this->path):
                    $this->container=&new odContainer_zip($this->path);
                    break;
            }
        }
        return $this->container;
    }/**/
    
    /**
    *
    * @param
    * @access protected
    * @return
    * /
    function () {

    }/**/
}
?>